package com.chao.juc.locak8;

import java.util.concurrent.TimeUnit;

/**
 * @author : Rookie
 * @description :
 * @date : 2022/1/18
 */
public class Test2 {
    public static void main(String[] args) {

        Phone2 phone = new Phone2();

        new Thread(() ->{
            phone.sendSms();
        },"A").start();

        try {
            TimeUnit.SECONDS.sleep(3);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        new Thread(() ->{
            phone.call();
        },"B").start();

        new Thread(() ->{
            phone.hello();
        },"C").start();
    }
}

class Phone2{

    public synchronized void sendSms(){
        System.out.println("发短信");
    }

    public synchronized void call(){
        System.out.println("打电话");
    }

    public void hello(){
        try {
            TimeUnit.SECONDS.sleep(4);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println("hello,world");
    }
}
